#include "StdAfx.h"
#include "MemoryHelper.h"

CMemoryHelper::CMemoryHelper(void)
{
}

CMemoryHelper::~CMemoryHelper(void)
{
}

DWORD CMemoryHelper::getPoint( DWORD point )
{
	DWORD result = NULL;
	_try
	{
		_asm
		{
			mov eax, point;
			mov eax, [eax]
			mov result, eax;
		}
	}
	_except(1)
	{
	}
	return result;
}


PCHAR CMemoryHelper::getString( DWORD point )
{
	PCHAR result = NULL;
	_try
	{
		_asm
		{
			mov eax, point;
			mov result, eax;
		}
	}
	_except(1)
	{
	}
	return result;
}

int CMemoryHelper::getInt( DWORD point )
{
	return (int)getPoint(point);
}

float CMemoryHelper::getFloat( DWORD point )
{
	DWORD d = getPoint(point);
	return *((float*)&d);
}

DWORD CMemoryHelper::commonCall( DWORD callAddress, int *pushPs, int pushCount, DWORD eaxP /*= NULL*/ )
{
	_try
	{
		_asm
		{
			push ecx;
			push edx;
			mov ecx, pushCount;
			mov edx, 1;
loop_sign_push_params:
			push [pushPs + edx];
			add edx, 1;
			loop loop_sign_push_params;
			mov eax, eaxP;
			call callAddress;
			pop edx;
			pop ecx;
		}
	}
	_except(1)
	{
		return NULL;
	}
}

byte CMemoryHelper::getByte(DWORD point)
{
	byte result = NULL;
	_try
	{
		_asm
		{
			mov eax, point;
			mov eax, [eax];
			mov result, al;
		}
	}
	_except(1)
	{
	}
	return result;
}